#include<stdio.h>
#include<unistd.h> //是close, write等这些接口的头文件
#include<string.h>
#include<fcntl.h> //是O_CREAT 这些宏的头文件
#include<sys/stat.h> //umask接口的头文件

int main()
{
    umask(0);
    int fd = open("./bite1",O_CREAT|O_RDWR, 0664);
    if(fd < 0)
    {
        perror("open error");
        return -1;
    }
    char *data = "i like linux!\n";
    ssize_t ret = write(fd, data, strlen(data));
    if(ret < 0)
    {
        perror("write error");
        return -1;
    }
    lseek(fd, 0, SEEK_SET);
    char buf[1024] = {0};
    ret = read(fd, buf, 1023);
    if(ret < 0)
    {
        perror("read error");
        return -1;
    }else if(ret == 0)
    {
        printf("end of file!\n");
        return -1;
    }
    printf("%s", buf);
    close(fd);
    return 0;
}
